#include <cstdio>

char s[ 1000001 ];
int next[ 1000001 ], a[ 1000001 ];

void getnext( char *s, int *next, int n )
{
    int i, j = -1;
    next[ 0 ] = -1;
    for ( i = 1; i < n; i++ )
    {
        while ( j >= 0 && s[ j + 1 ] != s[ i ] ) j = next[ j ];
        if ( s[ j + 1 ] == s[ i ] ) j++;
        next[ i ] = j;
    }
}

int main( )
{
    int n, i, cas = 1;
    while ( scanf("%d", &n) && n )
    {
        scanf("%s", s);
        getnext( s, next, n );
        a[ 0 ] = 1;
        for ( i = 1; i < n; i++ )
            if ( next[ i ] == -1 )
                a[ i ] = 1;
            else
                if ( i - next[ i ] == ( next[ i ] + 1 ) / a[ next[ i ] ] )
                    a[ i ] = a[ next[ i ] ] + 1;
                else
                    a[ i ] = 1;
        printf("Test case #%d\n", cas++);
        for ( i = 1; i < n; i++ )
            if ( a[ i ] > 1 )
                printf("%d %d\n", i + 1, a[ i ]);
        puts("");
    }
    return 0;
}
